package org.nobject.common.fan;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Set;

import org.nobject.common.file.FileUtils;

/**
 * 图片查找
 *
 * @author bianrongjun
 * @version 1.0
 */
public class ImageSearch {
	
	/**
	 * 剪取出图片
	 * 
	 * EXP:
	 * String path="D:\\SOU_HOME\\BEA_HOME";
	 * String destPath="D:\\WOR_HOME\\PS_WORKSPACE\\SOFT_ICON\\bea";
	 * pickupImage(path,destPath,"gif",true);
	 * pickupImage(path,destPath,"jpg",true);
	 * pickupImage(path,destPath,"png",true);
	 * 
	 * @param path
	 * @param destPath
	 * @param ext
	 * @param loop
	 * @throws IOException 
	 */
	public static void pickupImage(String path, String destPath, String ext,boolean loop) throws IOException{
		Set files = FileUtils.getSubFilePathes(path, new String[]{".*\\."+ext}, true);
		File dir=new File(destPath+File.separator+ext);
		if(!dir.exists()) dir.mkdirs();
		int idx=0;
		for (Iterator iterator = files.iterator(); iterator.hasNext();) {
			String filePath= (String) iterator.next();
			File file=new File(filePath);
			if(file.exists()){
				String filename=FileUtils.getFilePureName(file.getName());
				FileUtils.copyFile(filePath,dir.getAbsolutePath()+File.separator+filename+"_"+(idx++)+"."+ext);
			}
		}
		
	}
}
